package com.cmj.controller;

import com.cmj.annotation.SystemLog;
import com.cmj.domain.ResponseResult;
import com.cmj.domain.dto.UserDto;
import com.cmj.domain.dto.UserStatusDto;
import com.cmj.domain.entity.User;
import com.cmj.domain.vo.UserNewVo;
import com.cmj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户管理
 */
@RestController
@RequestMapping("/system/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public ResponseResult<UserNewVo> getUserList(Integer pageNum, Integer pageSize, UserDto userDto){
        return userService.getUserList(pageNum,pageSize,userDto);
    }

    @GetMapping("{id}")
    public ResponseResult getUser(@PathVariable("id") Long id){
        return userService.getUser(id);
    }

    @DeleteMapping("{ids}")
    public ResponseResult delUser(@PathVariable("ids") Long[] ids){
        return userService.delUser(ids);
    }


    @PutMapping
    @SystemLog(businessName = "更新用户")
    public ResponseResult updateUserInfo(@RequestBody User user){
        return userService.updateUser(user);
    }

    @PostMapping
    public ResponseResult addUser(@RequestBody User user){
        return userService.addUser(user);
    }

    @PutMapping("changeStatus")
    public ResponseResult changeStatus(@RequestBody UserStatusDto userStatusDto){
        return userService.changeStatus(userStatusDto);
    }
}
